﻿using System;
using System.Configuration;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cms.Application;
using Cms.Web.Framework.Controls;
using iLib.Web.UI;

namespace Cms.Web.UI.Admin
{
    public partial class PublicMaster : AdminBaseMaster, ITranslatable
    {
        #region ITranslatable Members

        public string ContextTranslationFile
        {
            get { return "Admin/Translations/PublicMaster.xml"; }
        }

        #endregion

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //_controller = new AdminMasterController(this);
            Response.HeaderEncoding = Encoding.UTF8;
            head.Controls.Add(new iLibRegistrator());
            if (!Page.IsPostBack)
            {
                form1.Action = Url.VirtualPath + Url.FoldersAndPage + Url.Querystring;
            }
            head.Controls.Add(new LiteralControl("<script language=\"javascript\" src=\"" +
                                                 Url.VirtualPath + "Admin/Js/CmsLib.js\"></script>"));
            head.Controls.Add(new LiteralControl("<script language=\"javascript\" src=\"" +
                                                 Url.VirtualPath + "Admin/Js/Dialogs.js\"></script>"));
            head.Controls.Add(new LiteralControl("<script language=\"javascript\" src=\"" +
                                                 Url.VirtualPath + "Admin/Js/Lists.js\"></script>"));
            form1.Controls.Add(new LiteralControl("<script language=\"javascript\" src=\"" +
                                                  Url.VirtualPath + "Admin/Js/InitPublicMaster.js?v=2\"></script>"));
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Page.Header.Controls.AddAt(
                0,
                new LiteralControl("<script type=\"text/javascript\" src=\"" + ConfigurationManager.AppSettings["jQueryPath"] + "\"></script>"));
        }

        protected void lbLocalization_Click(object sender, EventArgs e)
        {
            string localization = ((LinkButton) sender).CommandArgument;
            ViewState["Localization"] = localization;
            var cookie = new HttpCookie("FrediumAdminLocalization", localization)
                             {Expires = DateTime.Now.AddYears(1)};
            Response.Cookies.Add(cookie);
        }
    }
}